package com.eatme.web.app.coupon.settlement.controller;

import com.alibaba.fastjson2.JSON;
import com.eatme.web.app.coupon.common.exception.AppException;
import com.eatme.web.app.coupon.common.vo.SettlementInfo;
import com.eatme.web.app.coupon.settlement.executor.ExecuteManager;
import com.eatme.web.app.coupon.settlement.executor.impl.LiJianExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 结算服务 Controller
 * Created by Qinyi.
 */
@RestController
public class SettlementController {

    private static final Logger LOG = LoggerFactory.getLogger(LiJianExecutor.class);

    /** 结算规则执行管理器 */
    private final ExecuteManager executeManager;

    @Autowired
    public SettlementController(ExecuteManager executeManager) {
        this.executeManager = executeManager;
    }

    /**
     * 优惠券结算
     * 127.0.0.1:7003/settlement/settlement/compute
     * 127.0.0.1:9000/settlement/settlement/compute
     * */
    @PostMapping("/settlement/compute")
    public SettlementInfo computeRule(@RequestBody SettlementInfo settlement)
            throws AppException {
        LOG.info("settlement: {}", JSON.toJSONString(settlement));
        return executeManager.computeRule(settlement);
    }
}
